<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>货主主页 - 航运物流系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .header {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 20px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            margin-bottom: 30px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .logo h1 {
            color: #333;
            font-size: 24px;
        }
        
        .logo p {
            color: #666;
            font-size: 14px;
        }
        
        .user-info {
            text-align: right;
        }
        
        .user-info p {
            margin-bottom: 5px;
            color: #555;
        }
        
        .logout-btn {
            background: #e74c3c;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s ease;
        }
        
        .logout-btn:hover {
            background: #c0392b;
        }
        
        .content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
        }
        
        .panel {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .panel-title {
            font-size: 20px;
            color: #333;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid #667eea;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
        }
        
        .form-group input, .form-group textarea, .form-group select {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e1e1e1;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
        }
        
        .form-group input:focus, .form-group textarea:focus, .form-group select:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        
        .form-group textarea {
            min-height: 100px;
            resize: vertical;
        }
        
        .btn {
            padding: 12px 25px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        
        .shipments-list {
            max-height: 400px;
            overflow-y: auto;
        }
        
        .shipment-item {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 15px;
            margin-bottom: 15px;
            border-left: 4px solid #667eea;
            transition: all 0.3s ease;
        }
        
        .shipment-item:hover {
            background: #e9ecef;
            transform: translateX(5px);
        }
        
        .shipment-id {
            font-weight: bold;
            color: #333;
            margin-bottom: 5px;
        }
        
        .shipment-detail {
            color: #666;
            font-size: 14px;
            margin-bottom: 3px;
        }
        
        .status-badge {
            display: inline-block;
            padding: 3px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: bold;
        }
        
        .status-pending {
            background: #fff3cd;
            color: #856404;
        }
        
        .status-shipped {
            background: #d1ecf1;
            color: #0c5460;
        }
        
        .status-delivered {
            background: #d4edda;
            color: #155724;
        }
        
        .ship-icon {
            font-size: 24px;
            color: #667eea;
            margin-right: 10px;
        }
        
        .empty-message {
            text-align: center;
            color: #666;
            padding: 30px;
        }
        
        .error-message {
            color: #e74c3c;
            margin-top: 15px;
            font-size: 14px;
            display: none;
        }
        
        .success-message {
            color: #27ae60;
            margin-top: 15px;
            font-size: 14px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="logo">
                <h1>航运物流管理系统</h1>
                <p>货主操作平台</p>
            </div>
            <div class="user-info">
                <p>货主ID: <span id="userIdDisplay">-</span></p>
                <button class="logout-btn" onclick="logout()">退出登录</button>
            </div>
        </div>
        
        <div class="content">
            <div class="panel">
                <h2 class="panel-title"><span class="ship-icon">📦</span>我的物流信息</h2>
                <div class="shipments-list" id="shipmentsList">
                    <div class="empty-message">暂无物流信息</div>
                </div>
            </div>
            
            <div class="panel">
                <h2 class="panel-title"><span class="ship-icon">➕</span>创建物流订单</h2>
                <form id="createForm">
                    <div class="form-group">
                        <label for="carrierId">承运商ID</label>
                        <input type="number" id="carrierId" name="carrierId" required placeholder="请输入承运商ID">
                    </div>
                    
                    <div class="form-group">
                        <label for="from">起始地</label>
                        <input type="text" id="from" name="from" required placeholder="请输入起始地">
                    </div>
                    
                    <div class="form-group">
                        <label for="to">目的地</label>
                        <input type="text" id="to" name="to" required placeholder="请输入目的地">
                    </div>
                    
                    <button type="submit" class="btn">创建订单</button>
                    
                    <div class="error-message" id="createError"></div>
                    <div class="success-message" id="createSuccess"></div>
                </form>
            </div>
        </div>
    </div>

    <script>
        // 获取货主ID
        const userId = localStorage.getItem('userId');
        if (!userId) {
            window.location.href = 'user_login.html';
        } else {
            document.getElementById('userIdDisplay').textContent = userId;
            // 加载用户的物流信息
            loadUserShipments();
        }
        
        // 创建物流订单表单提交
        document.getElementById('createForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const carrierId = document.getElementById('carrierId').value;
            const from = document.getElementById('from').value;
            const to = document.getElementById('to').value;
            const createError = document.getElementById('createError');
            const createSuccess = document.getElementById('createSuccess');
            
            // 发送创建订单请求到后端
            fetch('http://172.21.136.66:8080/shipment/create', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ 
                    user_id: userId,
                    carrier_id: carrierId,
                    from: from,
                    to: to
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === '0') {
                    createSuccess.textContent = '物流订单创建成功！';
                    createSuccess.style.display = 'block';
                    createError.style.display = 'none';
                    
                    // 清空表单
                    document.getElementById('carrierId').value = '';
                    document.getElementById('from').value = '';
                    document.getElementById('to').value = '';
                    
                    setTimeout(() => {
                        createSuccess.style.display = 'none';
                    }, 3000);
                } else {
                    createError.textContent = '创建失败：' + (data.message || '未知错误');
                    createError.style.display = 'block';
                    createSuccess.style.display = 'none';
                }
            })
            .catch(error => {
                createError.textContent = '网络错误，请稍后重试';
                createError.style.display = 'block';
                createSuccess.style.display = 'none';
            });
        });
        
        // 加载用户的物流信息
        function loadUserShipments() {
            // 如果有相关接口，可以在这里实现加载用户物流信息的逻辑
            // 暂时留空，因为没有提供相关接口
        }

        // 退出登录
        function logout() {
            localStorage.removeItem('userId');
            window.location.href = 'user_login.html';
        }
    </script>
</body>
</html>